const { insertData, findData, updateData, deleteOneData, requstPromise, randomWord } = require('../utils')
const { updateUserInfo } = require('./user')
const crypto = require('crypto')

const LuckyDraw = {
    // 增加奖项
    async addLuckyDraw(option) {
        const { describe, describePic, title, award, probability } = option
        return requstPromise(await insertData('camluniLuckyDraw', {
            id: randomWord(false, 43),
            award, // 是否为奖品
            probability, // 抽中的概率
            describe, // 奖项介绍
            describePic,// 奖项图片
            title // 奖项名称
        }))
    },

    // 删除指定id
    async deleteLuckyDraw(id) {
        return requstPromise(await deleteOneData('camluniLuckyDraw', { id }))
    },

    // 
    async editLuckyDraw(option) {
        const { id, ...data } = option
        return requstPromise(await updateData('camluniLuckyDraw', { id }, { ...data }))
    },

    // 获取列表
    async findLuckyDraw(option) {
        return requstPromise(await findData('camluniLuckyDraw', { ...option }))
    },
}

module.exports = LuckyDraw
